package com.bookstore.back.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bookstore.back.entity.NewsCategoryRelation;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 新闻分类关系Mapper接口
 * 
 * @author 程序猿_Ti
 * @since 2025-07-23
 */
@Mapper
public interface NewsCategoryRelationMapper extends BaseMapper<NewsCategoryRelation> {

    /**
     * 根据分类ID获取新闻ID列表
     */
    @Select("SELECT news_id FROM news_category_relation WHERE category_id = #{categoryId}")
    List<Integer> getNewsIdsByCategoryId(@Param("categoryId") Integer categoryId);

    /**
     * 根据新闻ID获取分类ID列表
     */
    @Select("SELECT category_id FROM news_category_relation WHERE news_id = #{newsId}")
    List<Integer> getCategoryIdsByNewsId(@Param("newsId") Integer newsId);
}
